local table_name = "dungeon"
local old_table = IMPORT_D:get_table(table_name)
if not old_table then
    return
end

local attrib = IMPORT_D:get_table("dungeonattribute")
if not attrib then
    return
end

local new_table = {}
for _, tbl in pairs(attrib) do repeat
    local config = old_table[tbl.difficult]
    if not config then
        break
    end

    ---! 奖励表
    local reward_map = {
        [GamePropIds.kGamePropIdsCopperIcon] = tbl.rewardsNum1,
        [GamePropIds.kGamePropIdsDiamondsIcon] = tbl.rewardsNum2,
        [GamePropIds.kGamePropIdsSoulIcon] = tbl.rewardsNum3,
    }

    ---! 怪物表
    local monster_map = {}
    for round = 1, 3 do
        local monsters = tbl["monster"..round]
        if not monsters then
            break
        end

        local monster_tbl = {}
        for _, monster_id in ipairs(string.split(monsters, ";")) do
            monster_id = tonumber(monster_id)
            monster_tbl[monster_id] = (monster_tbl[monster_id] or 0) + 1
        end

        monster_map[round] = monster_tbl
    end

    ---! id，难度，等级
    local id, difficult, level = tbl.id, tbl.difficult, tbl.level

    ---! 解锁等级
    local unlock = config["unlockNum" .. difficult] or 0

    ---! 副本
    local dungeon = setmetatable({}, {__index = config})
    dungeon.id = id
    dungeon.level = level
    dungeon.unlock = unlock
    dungeon.reward = reward_map
    dungeon.monster = monster_map

    if new_table[level] then
        new_table[level][difficult] = dungeon
    else
        new_table[level] = { [difficult] = dungeon }
    end
until true end

IMPORT_D:set(table_name, new_table)
